/**
 * Created by Administrator on 2017/8/8 0008.
 */

var id="";

var motoroomFormatter = function(value,row,index){
    return ['<a href="javascript:void(0)" class="delete">删除</a>'+'&nbsp&nbsp&nbsp'+'<a href="javascript:void(0)" ' +
    'class="alter">修改</a>'].join('');
}


var uNameFormatter = function(value,row,index){
    return ['<a href="javascript:void(0)" class="nextGrade">'+row.mName+'</a>'].join('');
}

window.motoroomEvents={
    'click .delete':function(e,value,row,index){
            alert(value);
        comment.showOperationTips("确认要删除该设备吗？",function(){

            $.post($().AbsUrlParse('/web/motoroom/deleteMotoroomById'),{
                id: value
            }, function(data){
                if(data.state==true){
                    if(data.res.code==40000){
                        hint("删除该设备成功");
                        var table = $("#table");
                        table.bootstrapTable('refresh');
                    }else{
                        hint(data.res.msg);
                    }
                }else{
                    hint(data.msg);
                }
            });
        });
    },

    'click .alter':function(e,value,row,index){
        showModel("motoroomDetail",function(){
            setRowToFrm("motoroomDetailForm",row)
        });
        id = value;

    },

    'click .nextGrade':function(e,value,row,index){
          $.post($().AbsUrlParse("/web/motoroom/motoroomQueryNext?motoroomQueryNext="+row.wId),function(data){
             if(data.total!=0){

                 //这个是上面的目录导航
                 $('.mystyle').append('<span onclick="clearPathClick('+row.wId+')">' + row.mName + '>&nbsp;&nbsp;&nbsp;</span>');

                 var url = $().AbsUrlParse("/web/motoroom/motoroomQueryNext?motoroomQueryNext="+row.wId);

                 $("#table").bootstrapTable("refresh",{url:url});

                 $("#table").bootstrapTable("hideColumn", "m_type");
                 $("#table").bootstrapTable("hideColumn", "checkCycle");
             }else{
                 hint("下一级没有数据了")
             }
          });
    }
}

//目录导航
function clearPathClick(wId){
    var url = $().AbsUrlParse("/web/motoroom/motoroomQueryNext?motoroomQueryNext="+wId);
    $("#table").bootstrapTable("refresh",{url:url});
}
//修改提交表单
bindClick(".submitBtn",function(){
    var inputs = $("#motoroomDetailForm input");
    var flag = isNullForm(inputs);
    if(!flag){
        hint("请完整填写表单项");
        return false;
    }
    var arr= $("#motoroomDetailForm").formToArray();

    comment.post( $().AbsUrlParse("/web/motoroom/motoroomUpdateById?id="+id+""),
       arr
    ,function(data){
        hint("修改成功");
        closeModel("motoroomDetail");
        $("#table").bootstrapTable("refresh");
    });

})

//验证表单是否为空
function isNullForm(inputs){
    console.log(1);
    var isNullFormFlag = true;
    for(var i=0;i<inputs.length;i++){
        if(isNullFormFlag){
            var singleInput = $(inputs[i]);
            if(singleInput.val()==""||singleInput.val().trim()==""){
                isNullFormFlag = false;
                return isNullFormFlag;
            }
        }
    }
    return isNullFormFlag;
}


